//
//  MVPCountViewController.m
//  DebugDemo
//
//  Created by XFB on 2019/5/7.
//  Copyright © 2019 ZhouCheng. All rights reserved.
//

#import "MVPCountViewController.h"
#import "CountPresenter.h"
#import "CountModel.h"

@interface MVPCountViewController () <CountViewProtocol>
{
    CountPresenter *_presenter;
    UILabel *_vauleLabel;
}

@end

@implementation MVPCountViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"MVP计数器";

    [self setupUI];
    
    CountModel *countModel = [[CountModel alloc] init];
    _presenter = [[CountPresenter alloc] initWithModel:countModel countView:self];
    [_presenter getCurrentValue];
}

- (void)setupUI
{
    UIButton *increaseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    increaseButton.frame = CGRectMake(ScreenW/2-50, 100, 100, 50);
    [increaseButton setTitle:@"加" forState:UIControlStateNormal];
    [increaseButton addTarget:self action:@selector(increaseButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    increaseButton.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:increaseButton];
    
    UILabel *countLabel = [[UILabel alloc] init];
    countLabel.textAlignment = NSTextAlignmentCenter;
    countLabel.frame = CGRectMake(ScreenW/2-50, 200, 100, 50);
    countLabel.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:countLabel];
    _vauleLabel = countLabel;
    
    UIButton *decreaseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    decreaseButton.frame = CGRectMake(ScreenW/2-50, 300, 100, 50);
    [decreaseButton setTitle:@"减" forState:UIControlStateNormal];
    [decreaseButton addTarget:self action:@selector(decreaseButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    decreaseButton.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:decreaseButton];
}

/// 加
- (void)increaseButtonDidClick
{
    [_presenter increaseCount];
}

/// 减
- (void)decreaseButtonDidClick
{
    [_presenter decreaseCount];
}

#pragma mark --- <CountViewProtocol>
- (void)updateCountValue:(NSString *)value
{
    _vauleLabel.text = value;
}

@end
